import {getInspectionitemdefectList,getDefactAll} from '@/api/q1/business/inspection/defect.js'
const state = {
    defectList:[],
}

const mutations = {
	SET_DEFECT_LIST:(state, defectList) => {
	        state.defectList = defectList
	}
}

const actions = {
	 getDefactAll({ commit }) {
	        return new Promise((resolve, reject) => {
	            getDefactAll().then(res => {
	                commit('SET_DEFECT_LIST', res.data.list)
	                resolve(res.data.list)
	            }).catch(error => {
	                reject(error)
	            })
	        })
	},
	getDefactData({ state, dispatch }) {
	        return new Promise(async resolve => {
	            let list = []
	            if (!state.defectList.length) {
	                list = await dispatch('getDefactAll')
	            } else {
	                list = state.defectList
	            }
	            resolve(list)
	        })
	    }
}


export default {
    namespaced: true,
    state,
    mutations,
    actions
}